<?php
/**
 * @version      BOSSCMS-Free
 * @trademark    BOSSCMS
 * @copyright    Copyright © by BOSSCMS-Free (https://www.bosscms.net/) 保留所有权利
 * @license      https://gitee.com/Greenpeas/BOSSCMS/license/ 和 https://www.bosscms.net/freelicense/
 * @link         https://www.bosscms.net/
 * @author       温州软界网络技术有限公司
**/
defined('IS_OK') or exit('Access Forbidden');

into::basic_class('admin');

// b o s s c m s
class home extends admin
{
	public function init()
	{
		global $G;
		$data['shortcut'] = json::decode($G['config']['shortcut']);
		foreach($data['shortcut'] as $k=>$v){
			$link = explode('&',$v['link']);
			$data['shortcut'][$k]['name'] = $v['name'];
			$data['shortcut'][$k]['url'] = url::mpf($link[0], $link[1]?$link[1]:$link[0], $link[2]?$link[2]:'init');
		}
		echo $this->theme('home/home',$data);
	}

	public function total()
	{
		global $G;
		switch($G['get']['type']){
			case 2:
			case 3:
			case 4:
			case 5:
				echo mysql::total(array_search($G['get']['type'],$G['pass']['type']),"display=1");
				break;
			case '2m':
			case '3m':
			case '4m':
			case '5m':
				echo mysql::total(array_search(str_replace('m','',$G['get']['type']),$G['pass']['type']),"display=1 AND ctime>=".strtotime(date('Y-m-d',TIME)));
				break;
				break;
			case '2t':
			case '3t':
			case '4t':
			case '5t':
				echo mysql::total('tag',"type='".str_replace('t','',$G['get']['type'])."'");
				break;
			case 'l':
				echo mysql::total('link',"display=1");
				break;
			case 'lt':
				echo mysql::total('link',"display=1 AND type=0");
				break;
			case 'li':
				echo mysql::total('link',"display=1 AND type=1");
				break;
		}
	}
	
	public function develop()
	{
		global $G;
		header('content-type:application/json;charset=utf-8');
		into::basic_class('curl');
		$file = ROOT_PATH.'cache/json/bosscms_develop.json';
		if(is_file($file)){
			$res = file_get_contents($file);
		}else{
			$res = curl::request('https://api.bosscms.net/rest/develop/?auth=free&version='.$G['config']['version']);
			dir::create($file, $res);
		}
		echo $res;
	}
}
?>